package com.room.search.web.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.room.search.IntegrationTest;
import com.room.search.domain.RoomCommunity;
import com.room.search.repository.RoomCommunityRepository;
import com.room.search.service.dto.RoomCommunityDTO;
import com.room.search.service.mapper.RoomCommunityMapper;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

/**
 * Integration tests for the {@link RoomCommunityResource} REST controller.
 */
@IntegrationTest
@AutoConfigureMockMvc
@WithMockUser
class RoomCommunityResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBB";

    private static final String DEFAULT_AVERAGE = "AAAAAAAAAA";
    private static final String UPDATED_AVERAGE = "BBBBBBBBBB";

    private static final String DEFAULT_BUILDING_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_BUILDING_TYPE = "BBBBBBBBBB";

    private static final String DEFAULT_PROPERTY_COSTS = "AAAAAAAA";
    private static final String UPDATED_PROPERTY_COSTS = "BBBBBBBB";

    private static final String DEFAULT_PROPERTY_COMPANY = "AAAAAAAAAA";
    private static final String UPDATED_PROPERTY_COMPANY = "BBBBBBBBBB";

    private static final String DEFAULT_DEVELOPER = "AAAAAAAAAA";
    private static final String UPDATED_DEVELOPER = "BBBBBBBBBB";

    private static final String DEFAULT_BUILDING_NO = "AAAAAAAA";
    private static final String UPDATED_BUILDING_NO = "BBBBBBBB";

    private static final String DEFAULT_ROOM_NO = "AAAAAAAA";
    private static final String UPDATED_ROOM_NO = "BBBBBBBB";

    private static final String DEFAULT_NEARBY_STORES = "AAAAAAAAAA";
    private static final String UPDATED_NEARBY_STORES = "BBBBBBBBBB";

    private static final String DEFAULT_FOCUS_NO = "AAAAAAAA";
    private static final String UPDATED_FOCUS_NO = "BBBBBBBB";

    private static final String ENTITY_API_URL = "/api/room-communities";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong count = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));

    @Autowired
    private RoomCommunityRepository roomCommunityRepository;

    @Autowired
    private RoomCommunityMapper roomCommunityMapper;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restRoomCommunityMockMvc;

    private RoomCommunity roomCommunity;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomCommunity createEntity(EntityManager em) {
        RoomCommunity roomCommunity = new RoomCommunity()
            .name(DEFAULT_NAME)
            .average(DEFAULT_AVERAGE)
            .buildingType(DEFAULT_BUILDING_TYPE)
            .propertyCosts(DEFAULT_PROPERTY_COSTS)
            .propertyCompany(DEFAULT_PROPERTY_COMPANY)
            .developer(DEFAULT_DEVELOPER)
            .buildingNo(DEFAULT_BUILDING_NO)
            .roomNo(DEFAULT_ROOM_NO)
            .nearbyStores(DEFAULT_NEARBY_STORES)
            .focusNo(DEFAULT_FOCUS_NO);
        return roomCommunity;
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomCommunity createUpdatedEntity(EntityManager em) {
        RoomCommunity roomCommunity = new RoomCommunity()
            .name(UPDATED_NAME)
            .average(UPDATED_AVERAGE)
            .buildingType(UPDATED_BUILDING_TYPE)
            .propertyCosts(UPDATED_PROPERTY_COSTS)
            .propertyCompany(UPDATED_PROPERTY_COMPANY)
            .developer(UPDATED_DEVELOPER)
            .buildingNo(UPDATED_BUILDING_NO)
            .roomNo(UPDATED_ROOM_NO)
            .nearbyStores(UPDATED_NEARBY_STORES)
            .focusNo(UPDATED_FOCUS_NO);
        return roomCommunity;
    }

    @BeforeEach
    public void initTest() {
        roomCommunity = createEntity(em);
    }

    @Test
    @Transactional
    void createRoomCommunity() throws Exception {
        int databaseSizeBeforeCreate = roomCommunityRepository.findAll().size();
        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);
        restRoomCommunityMockMvc
            .perform(
                post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isCreated());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeCreate + 1);
        RoomCommunity testRoomCommunity = roomCommunityList.get(roomCommunityList.size() - 1);
        assertThat(testRoomCommunity.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testRoomCommunity.getAverage()).isEqualTo(DEFAULT_AVERAGE);
        assertThat(testRoomCommunity.getBuildingType()).isEqualTo(DEFAULT_BUILDING_TYPE);
        assertThat(testRoomCommunity.getPropertyCosts()).isEqualTo(DEFAULT_PROPERTY_COSTS);
        assertThat(testRoomCommunity.getPropertyCompany()).isEqualTo(DEFAULT_PROPERTY_COMPANY);
        assertThat(testRoomCommunity.getDeveloper()).isEqualTo(DEFAULT_DEVELOPER);
        assertThat(testRoomCommunity.getBuildingNo()).isEqualTo(DEFAULT_BUILDING_NO);
        assertThat(testRoomCommunity.getRoomNo()).isEqualTo(DEFAULT_ROOM_NO);
        assertThat(testRoomCommunity.getNearbyStores()).isEqualTo(DEFAULT_NEARBY_STORES);
        assertThat(testRoomCommunity.getFocusNo()).isEqualTo(DEFAULT_FOCUS_NO);
    }

    @Test
    @Transactional
    void createRoomCommunityWithExistingId() throws Exception {
        // Create the RoomCommunity with an existing ID
        roomCommunity.setId(1L);
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        int databaseSizeBeforeCreate = roomCommunityRepository.findAll().size();

        // An entity with an existing ID cannot be created, so this API call must fail
        restRoomCommunityMockMvc
            .perform(
                post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllRoomCommunities() throws Exception {
        // Initialize the database
        roomCommunityRepository.saveAndFlush(roomCommunity);

        // Get all the roomCommunityList
        restRoomCommunityMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(roomCommunity.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].average").value(hasItem(DEFAULT_AVERAGE)))
            .andExpect(jsonPath("$.[*].buildingType").value(hasItem(DEFAULT_BUILDING_TYPE)))
            .andExpect(jsonPath("$.[*].propertyCosts").value(hasItem(DEFAULT_PROPERTY_COSTS)))
            .andExpect(jsonPath("$.[*].propertyCompany").value(hasItem(DEFAULT_PROPERTY_COMPANY)))
            .andExpect(jsonPath("$.[*].developer").value(hasItem(DEFAULT_DEVELOPER)))
            .andExpect(jsonPath("$.[*].buildingNo").value(hasItem(DEFAULT_BUILDING_NO)))
            .andExpect(jsonPath("$.[*].roomNo").value(hasItem(DEFAULT_ROOM_NO)))
            .andExpect(jsonPath("$.[*].nearbyStores").value(hasItem(DEFAULT_NEARBY_STORES)))
            .andExpect(jsonPath("$.[*].focusNo").value(hasItem(DEFAULT_FOCUS_NO)));
    }

    @Test
    @Transactional
    void getRoomCommunity() throws Exception {
        // Initialize the database
        roomCommunityRepository.saveAndFlush(roomCommunity);

        // Get the roomCommunity
        restRoomCommunityMockMvc
            .perform(get(ENTITY_API_URL_ID, roomCommunity.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(roomCommunity.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.average").value(DEFAULT_AVERAGE))
            .andExpect(jsonPath("$.buildingType").value(DEFAULT_BUILDING_TYPE))
            .andExpect(jsonPath("$.propertyCosts").value(DEFAULT_PROPERTY_COSTS))
            .andExpect(jsonPath("$.propertyCompany").value(DEFAULT_PROPERTY_COMPANY))
            .andExpect(jsonPath("$.developer").value(DEFAULT_DEVELOPER))
            .andExpect(jsonPath("$.buildingNo").value(DEFAULT_BUILDING_NO))
            .andExpect(jsonPath("$.roomNo").value(DEFAULT_ROOM_NO))
            .andExpect(jsonPath("$.nearbyStores").value(DEFAULT_NEARBY_STORES))
            .andExpect(jsonPath("$.focusNo").value(DEFAULT_FOCUS_NO));
    }

    @Test
    @Transactional
    void getNonExistingRoomCommunity() throws Exception {
        // Get the roomCommunity
        restRoomCommunityMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putNewRoomCommunity() throws Exception {
        // Initialize the database
        roomCommunityRepository.saveAndFlush(roomCommunity);

        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();

        // Update the roomCommunity
        RoomCommunity updatedRoomCommunity = roomCommunityRepository.findById(roomCommunity.getId()).get();
        // Disconnect from session so that the updates on updatedRoomCommunity are not directly saved in db
        em.detach(updatedRoomCommunity);
        updatedRoomCommunity
            .name(UPDATED_NAME)
            .average(UPDATED_AVERAGE)
            .buildingType(UPDATED_BUILDING_TYPE)
            .propertyCosts(UPDATED_PROPERTY_COSTS)
            .propertyCompany(UPDATED_PROPERTY_COMPANY)
            .developer(UPDATED_DEVELOPER)
            .buildingNo(UPDATED_BUILDING_NO)
            .roomNo(UPDATED_ROOM_NO)
            .nearbyStores(UPDATED_NEARBY_STORES)
            .focusNo(UPDATED_FOCUS_NO);
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(updatedRoomCommunity);

        restRoomCommunityMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomCommunityDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isOk());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
        RoomCommunity testRoomCommunity = roomCommunityList.get(roomCommunityList.size() - 1);
        assertThat(testRoomCommunity.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testRoomCommunity.getAverage()).isEqualTo(UPDATED_AVERAGE);
        assertThat(testRoomCommunity.getBuildingType()).isEqualTo(UPDATED_BUILDING_TYPE);
        assertThat(testRoomCommunity.getPropertyCosts()).isEqualTo(UPDATED_PROPERTY_COSTS);
        assertThat(testRoomCommunity.getPropertyCompany()).isEqualTo(UPDATED_PROPERTY_COMPANY);
        assertThat(testRoomCommunity.getDeveloper()).isEqualTo(UPDATED_DEVELOPER);
        assertThat(testRoomCommunity.getBuildingNo()).isEqualTo(UPDATED_BUILDING_NO);
        assertThat(testRoomCommunity.getRoomNo()).isEqualTo(UPDATED_ROOM_NO);
        assertThat(testRoomCommunity.getNearbyStores()).isEqualTo(UPDATED_NEARBY_STORES);
        assertThat(testRoomCommunity.getFocusNo()).isEqualTo(UPDATED_FOCUS_NO);
    }

    @Test
    @Transactional
    void putNonExistingRoomCommunity() throws Exception {
        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();
        roomCommunity.setId(count.incrementAndGet());

        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomCommunityMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomCommunityDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchRoomCommunity() throws Exception {
        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();
        roomCommunity.setId(count.incrementAndGet());

        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomCommunityMockMvc
            .perform(
                put(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamRoomCommunity() throws Exception {
        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();
        roomCommunity.setId(count.incrementAndGet());

        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomCommunityMockMvc
            .perform(
                put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateRoomCommunityWithPatch() throws Exception {
        // Initialize the database
        roomCommunityRepository.saveAndFlush(roomCommunity);

        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();

        // Update the roomCommunity using partial update
        RoomCommunity partialUpdatedRoomCommunity = new RoomCommunity();
        partialUpdatedRoomCommunity.setId(roomCommunity.getId());

        partialUpdatedRoomCommunity
            .average(UPDATED_AVERAGE)
            .propertyCosts(UPDATED_PROPERTY_COSTS)
            .buildingNo(UPDATED_BUILDING_NO)
            .roomNo(UPDATED_ROOM_NO)
            .nearbyStores(UPDATED_NEARBY_STORES)
            .focusNo(UPDATED_FOCUS_NO);

        restRoomCommunityMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomCommunity.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomCommunity))
            )
            .andExpect(status().isOk());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
        RoomCommunity testRoomCommunity = roomCommunityList.get(roomCommunityList.size() - 1);
        assertThat(testRoomCommunity.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testRoomCommunity.getAverage()).isEqualTo(UPDATED_AVERAGE);
        assertThat(testRoomCommunity.getBuildingType()).isEqualTo(DEFAULT_BUILDING_TYPE);
        assertThat(testRoomCommunity.getPropertyCosts()).isEqualTo(UPDATED_PROPERTY_COSTS);
        assertThat(testRoomCommunity.getPropertyCompany()).isEqualTo(DEFAULT_PROPERTY_COMPANY);
        assertThat(testRoomCommunity.getDeveloper()).isEqualTo(DEFAULT_DEVELOPER);
        assertThat(testRoomCommunity.getBuildingNo()).isEqualTo(UPDATED_BUILDING_NO);
        assertThat(testRoomCommunity.getRoomNo()).isEqualTo(UPDATED_ROOM_NO);
        assertThat(testRoomCommunity.getNearbyStores()).isEqualTo(UPDATED_NEARBY_STORES);
        assertThat(testRoomCommunity.getFocusNo()).isEqualTo(UPDATED_FOCUS_NO);
    }

    @Test
    @Transactional
    void fullUpdateRoomCommunityWithPatch() throws Exception {
        // Initialize the database
        roomCommunityRepository.saveAndFlush(roomCommunity);

        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();

        // Update the roomCommunity using partial update
        RoomCommunity partialUpdatedRoomCommunity = new RoomCommunity();
        partialUpdatedRoomCommunity.setId(roomCommunity.getId());

        partialUpdatedRoomCommunity
            .name(UPDATED_NAME)
            .average(UPDATED_AVERAGE)
            .buildingType(UPDATED_BUILDING_TYPE)
            .propertyCosts(UPDATED_PROPERTY_COSTS)
            .propertyCompany(UPDATED_PROPERTY_COMPANY)
            .developer(UPDATED_DEVELOPER)
            .buildingNo(UPDATED_BUILDING_NO)
            .roomNo(UPDATED_ROOM_NO)
            .nearbyStores(UPDATED_NEARBY_STORES)
            .focusNo(UPDATED_FOCUS_NO);

        restRoomCommunityMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomCommunity.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomCommunity))
            )
            .andExpect(status().isOk());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
        RoomCommunity testRoomCommunity = roomCommunityList.get(roomCommunityList.size() - 1);
        assertThat(testRoomCommunity.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testRoomCommunity.getAverage()).isEqualTo(UPDATED_AVERAGE);
        assertThat(testRoomCommunity.getBuildingType()).isEqualTo(UPDATED_BUILDING_TYPE);
        assertThat(testRoomCommunity.getPropertyCosts()).isEqualTo(UPDATED_PROPERTY_COSTS);
        assertThat(testRoomCommunity.getPropertyCompany()).isEqualTo(UPDATED_PROPERTY_COMPANY);
        assertThat(testRoomCommunity.getDeveloper()).isEqualTo(UPDATED_DEVELOPER);
        assertThat(testRoomCommunity.getBuildingNo()).isEqualTo(UPDATED_BUILDING_NO);
        assertThat(testRoomCommunity.getRoomNo()).isEqualTo(UPDATED_ROOM_NO);
        assertThat(testRoomCommunity.getNearbyStores()).isEqualTo(UPDATED_NEARBY_STORES);
        assertThat(testRoomCommunity.getFocusNo()).isEqualTo(UPDATED_FOCUS_NO);
    }

    @Test
    @Transactional
    void patchNonExistingRoomCommunity() throws Exception {
        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();
        roomCommunity.setId(count.incrementAndGet());

        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomCommunityMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, roomCommunityDTO.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchRoomCommunity() throws Exception {
        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();
        roomCommunity.setId(count.incrementAndGet());

        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomCommunityMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamRoomCommunity() throws Exception {
        int databaseSizeBeforeUpdate = roomCommunityRepository.findAll().size();
        roomCommunity.setId(count.incrementAndGet());

        // Create the RoomCommunity
        RoomCommunityDTO roomCommunityDTO = roomCommunityMapper.toDto(roomCommunity);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomCommunityMockMvc
            .perform(
                patch(ENTITY_API_URL)
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomCommunityDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomCommunity in the database
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteRoomCommunity() throws Exception {
        // Initialize the database
        roomCommunityRepository.saveAndFlush(roomCommunity);

        int databaseSizeBeforeDelete = roomCommunityRepository.findAll().size();

        // Delete the roomCommunity
        restRoomCommunityMockMvc
            .perform(delete(ENTITY_API_URL_ID, roomCommunity.getId()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<RoomCommunity> roomCommunityList = roomCommunityRepository.findAll();
        assertThat(roomCommunityList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
